package com.qf.six.ssm.controller.manager;

import com.qf.six.ssm.commen.request.ManagerParam;
import com.qf.six.ssm.commen.vo.ResponseResult;
import com.qf.six.ssm.entity.Manager;
import com.qf.six.ssm.service.manager.ManagerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZL
 */
@RestController
@RequestMapping("/man")
public class ManagerController {
    @Resource
    ManagerService managerService;

    /**
     * 修改功能
     *
     * @return
     */
    @GetMapping("/update")
    public ResponseResult<Integer> update(ManagerParam param) {
        Integer update = managerService.update(param);
        if (update > 0) {
            return ResponseResult.success(update);
        }
        return ResponseResult.error();
    }

    /**
     * 假删除
     *
     * @param uid
     * @return
     */
    @GetMapping("/delete")
    public ResponseResult<Integer> delete(Long uid) {
        Integer delete = managerService.falseDelete(uid);
        if (delete > 0) {
            return ResponseResult.success(delete);
        }
        return ResponseResult.error();
    }

    /**
     * 注册功能
     *
     * @param managerParam
     * @return
     */
    @GetMapping("/register")
    public ResponseResult<Integer> register(ManagerParam managerParam) {
        Integer register = managerService.register(managerParam);
        if (register > 0) {
            return ResponseResult.success(register);
        }
        return ResponseResult.error();
    }

    /**
     * 查询所有用户信息
     *
     * @return
     */
    @GetMapping("/select/all/manager")
    public ResponseResult<List<Manager>> selectAllManager() {
        List<Manager> managers = managerService.selectAllManager();
        return ResponseResult.success(managers);
    }
}
